package com.cs252.flashcardz;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MakeCard extends Activity implements OnClickListener{
	public EditText subject, title, front, cardback;
	public CallDatabase send;
	public Button submit;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.make_card);
		submit = (Button) findViewById(R.id.submit);
		subject = (EditText) findViewById(R.id.subject);
		title = (EditText) findViewById(R.id.title);
		front = (EditText) findViewById(R.id.front);
		cardback = (EditText) findViewById(R.id.cardback);
		
		submit.setOnClickListener(this);
	}
	
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if(v.getId() == R.id.submit && subject.getText().length()*title.getText().length()*front.getText().length()*cardback.getText().length() != 0){
			send = new CallDatabase();
			send.addCard(subject.getText().toString(), title.getText().toString(), front.getText().toString(), cardback.getText().toString());
			
			Thread subList = new Thread(){
				public void run(){
					Intent openSubjectList = new Intent("com.cs252.flashcardz.SUBJECTLIST");
					startActivity(openSubjectList);
					
				}
			};
			subList.start();
		}else{
			Toast.makeText(this, "Please complete all fields", Toast.LENGTH_SHORT).show();
		}
		
	}
	
	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		finish();
	}
	
	
	
	
	

}
